<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/bupma-v2.css" rel="stylesheet" type="text/css" />
<?php include("scripts/tweet_parse.php"); ?>
</head>

<body>

<?php
//define the path as relative
$path = "private";
$webpath ="http://localhost/bupma-v2/";
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
$i = 0;

echo "Directory Listing of $webpath$path<br/>";

list_dir($dir_handle,$path,$i);

function list_dir($dir_handle,$path,$counter)
{
    // print_r ($dir_handle);
    echo "<table width='100%' cellpadding='25' cellspacing='0' border='1'><tr>";
    //running the while loop
    while (false !== ($file = readdir($dir_handle))) {		
		$dir =$path.'/'.$file;
        if(is_dir($dir) && $file != '.' && $file !='..' ) {
            $handle = @opendir($dir) or die("undable to open file $file");
            echo "<td><a href='$webpath.$file'><img src='".$webpath."img/generic.png' align='absmiddle'>$file</a></td>";
            list_dir($handle, $dir, $counter);
        } elseif($file != '.' && $file !='..') {
        	echo "<td><a href='$webpath.$file'><img src='".$webpath."img/generic.png' align='absmiddle'>$file</a></td>";
			$counter++;
        }
		
		if ($counter % 4 == 0) {
			echo "</tr><tr>";	
		}
    }
    
    echo "</tr></table>";

    //closing the directory
    closedir($dir_handle);
    
}
?>

</body>
</html>